/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021.
 * Description: This file contains API find_trustlist_symbols that
 *	can export symbols in trustlist.
 * Author: yingelin <yingelin@huawei.com>
 * Create: 2021-01-30
 */

#include<linux/kallsyms.h>
#include <linux/bsearch.h>

static int compare(const void *name, const void *list)
{
	return strcmp(name, *(char **)list);
}

static char *list[] = {
	"",
#include CONFIG_RTOS_TRUSTLIST_SYMBOLS
};

/*
 * The trustlist is only readable, so can be accessed concurrently.
 */
unsigned long find_trustlist_symbols(const char *name)
{
	if (name == NULL)
		return 0;

	if (bsearch((const void *)name, (const void *)list, ARRAY_SIZE(list), sizeof(char *), compare))
		return kallsyms_lookup_name(name);
	return 0;
}
EXPORT_SYMBOL_NS(find_trustlist_symbols, HW_RTOS_NS);
